﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_OrderDetails : IOrderDetails
    {
        public void Add(OrderDetails item)
        {
            CakeEntities db = new CakeEntities();
            db.OrderDetails.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.OrderDetails.Remove(db.OrderDetails.Find(id));
            db.SaveChanges();
        }

        public OrderDetails FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.OrderDetails.Find(id);
        }

        public List<OrderDetails> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.OrderDetails.ToList();
        }

        public void Updata(int id, OrderDetails item)
        {
            CakeEntities db = new CakeEntities();
            var data= db.OrderDetails.Find(id);
            if (data != null )
            {
                data.Price= item.Price;
                data.Num=item.Num;
                data.OrderId=item.OrderId;
                data.Picture=item.Picture;
                data.SizeId=item.SizeId;
                db.SaveChanges();
            }
        }
    }
}
